package com.example.dnfgamercommunitybackend.controller;

import com.example.dnfgamercommunitybackend.service.ArticleLikesService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
public class ArticleLikesController {
    @Resource
    private ArticleLikesService articleLikesService;

    @PreAuthorize("hasAuthority('user:like_article')")
    @GetMapping("/likes/addLike")
    //点赞功能
    public String addLike(@RequestParam("articleId") int articleId, HttpServletRequest request){
        String token = request.getHeader("Authorization");
        return articleLikesService.addLike(articleId,token);
    }

    //取消点赞
    @PreAuthorize("hasAuthority('user:like_cancel_like')")
    @GetMapping("/likes/cancelLike")
    public String cancelLike(@RequestParam("articleId") int articleId,HttpServletRequest request){
        return articleLikesService.cancelLike(articleId,request.getHeader("Authorization"));
    }
}
